330A - Cakeminator - CodeForces Solution


brute force implementation *800

Please click on ads to support us..

Python Code:

import math as mt
from collections import defaultdict,deque
from posixpath import split
import sys
from bisect import bisect_right as b_r
from bisect import bisect_left as b_l



mod=1000000007
INT_MAX = sys.maxsize-1
INT_MIN = -sys.maxsize

def solve():
    n,m=map(int,input().split())
    a=[input() for i in range(n)]

    ans=0
    row=0
    for i in range(n):
        s=0
        for j in range(m):
            if(a[i][j]=="S"):
                s+=1
        if(not s):
            ans+=m
            row+=1
    
    col=0
    for i in range(m):
        s=0
        for j in range(n):
            if(a[j][i]=="S"):
                s+=1
        if(not s):
            ans+=(n-row)

    return ans

if __name__ == "__main__":
        print(solve())

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void dfs(int node,vector<int> &vis,vector<vector<int>> &adj,vector<int> &v){
    v.push_back(node);
    vis[node]=1;
    for(auto it:adj[node]){
        if(!vis[it]){
            dfs(it,vis,adj,v);
        }
    }
}

void solve(){
        int n,m;
        cin>>n>>m;

        char A[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin>>A[i][j];
            }
        }
       for(int i=0;i<n;i++){
        int j;
        for(j=0;j<m;j++){
            if(A[i][j]=='S')
            break;
        }
        if(j==m){
            for(j=0;j<m;j++)
            A[i][j]='e';
        }
       }

      for(int i=0;i<m;i++){
        int j;
        for(j=0;j<n;j++){
            if(A[j][i]=='S')
            break;
        }
        if(j==n){
            for(int j=0;j<n;j++)
            A[j][i]='e';
        }
      }

        int count=0;
       for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(A[i][j]=='e')
            count++;
        }
       }

       cout<<count<<endl;
}

int32_t main()
{
ios_base::sync_with_stdio(false);
 cin.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}


Comments

Submit
0 Comments
More Questions

1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya